package javax.per.toolkit.tools;


import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class Log {
	
	
	
	public static enum LogLevel{DEBUG,INFO,WARN,ERROR,FATAL,TRACE,OFF};
	
	static{
		PropertyConfigurator.configure(Log.class.getResource("log.properties"));
	}
	
	public static org.apache.log4j.Logger getLogger(){
		Class<?> cl = null;
		try {
			cl = Fun.getInvokerSuperClass();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		if(cl!=null)
			return org.apache.log4j.Logger.getLogger(cl);
		else{
			Logger.getLogger(Log.class).warn("Can't find super class.");
			return Logger.getRootLogger();
		}
	}
	
	public static org.apache.log4j.Logger getLogger(String name){
		return Logger.getLogger(name);
	}
	
	
	@Deprecated
	public static org.apache.log4j.Logger getLogger(Class<?> clazz){
		return org.apache.log4j.Logger.getLogger(clazz);
	}
	
	public static void setLevel(LogLevel level){
		Level le=Level.toLevel(level.toString());
		Class<?> cl = null;
		try {
			cl = Fun.getInvokerSuperClass();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		if(cl!=null)
			org.apache.log4j.Logger.getLogger(cl).setLevel(le);
		else{
			Logger.getLogger(Log.class).warn("Can't find super class.");
		}
	}
	
	@Deprecated
	public static void setLevel(Class<?> clazz,LogLevel level){
		Level le=Level.toLevel(level.toString());
		org.apache.log4j.Logger.getLogger(clazz).setLevel(le);
	}
	
	public static org.apache.log4j.Logger getRootLogger(){
		return Logger.getRootLogger();
	}
	
	
}
